package com.briup.web;

import com.briup.util.ResponseUtil;
import com.zhenzi.sms.ZhenziSmsClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class Message {
    @GetMapping("/message")
    public ResponseUtil message(String name, String telephone,
                          String city,String weather,String low,
                          String high)throws Exception{
        String apiUrl ="https://sms_developer.zhenzikj.com";
        String appId ="105250";
        String appSecret="c1b3830d-e3ed-4c69-98dc-2b72ce054488";
        ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("number", telephone);
        params.put("templateId", "384");
        String[] templateParams = new String[6];
        templateParams[0] = telephone;
        templateParams[1] = name;
        templateParams[2] = city;
        templateParams[3] = weather;
        templateParams[4] = low;
        templateParams[5] = high;

        params.put("templateParams", templateParams);
        String result = client.send(params);

        ResponseUtil responseUtil = ResponseUtil.ok(result);
        return responseUtil;
    }
}
